<!DOCTYPE html>
<html>
<head>
<title>{$site_name}-修改密码-个人中心</title>
<meta name="keywords" content="{$site_seo_keywords}" />
<meta name="description" content="{$site_seo_description}">

<tc_include file="Public:head" />
</head>
<body class="body-white" id="top">
	<tc_include file="Public:nav" />
		<div class="container tc-main">
        <div class="row">
            <div class="span2">
                <tc_include file="Public:usernav"/>
            </div>
            <div class="span10">
               	<tc_include file="Public:profilenav"/>
                <div class="tab-content">
                   <div class="tab-pane active" id="one">
                   		<form class="form-horizontal js-pwd-form" action="{:leuu('profile/password_post')}" method="post">
                   			<div class="control-group">
                   				<label class="control-label" for="input-old_password">原始密码</label>
                   				<div class="controls">
                   					<input type="password" id="input-old_password" placeholder="原始密码" name="old_password">
									<span class="help-inline"></span>
								</div>
                   			</div>
                   			<div class="control-group">
                   				<label class="control-label" for="input-password">新密码</label>
                   				<div class="controls">
                   					<input type="password" id="input-password" placeholder="新密码" name="password">
									<span class="help-inline"></span>
								</div>
                   			</div>
                   			<div class="control-group">
                   				<label class="control-label" for="input-repassword">重复密码</label>
                   				<div class="controls">
                   					<input type="password" id="input-repassword" placeholder="重复密码" name="repassword">
									<span class="help-inline"></span>
								</div>
                   			</div>
                   			<div class="control-group">
                   				<div class="controls">
                   					<button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
                   				</div>
                   			</div>
                   		</form>
                   </div>
               </div>						
            </div>
        </div>
		<tc_include file="Public:footer" />
	</div>
	<!-- /container -->

	<tc_include file="Public:scripts" />
	<script type="text/javascript">
	var pwdmessage = {
		old_password: {focusmsg : '请输入账号原密码'},
		password : {focusmsg : '建议使用字母、数字和符号两种以上的组合, 6-20个字符'},
		repassword : {focusmsg : '请再次输入密码确认'}
	}
	$(function() {
		var Form_list = $('.js-pwd-form');
		if (Form_list.length) {
			Wind.use('validate', 'ajaxForm', 'noty', function() {
				var form = $('form.js-pwd-form');
				form.find('input[type!=hidden]').each(function() {
					$(this).bind('focus', function() {
						var wrap = $(this).parent().parent();
						if(wrap.hasClass('error')) {
							wrap.removeClass('error');
						}
						var fieldname = $(this).attr('name');
						$(this).siblings('span[class=help-inline]').text(pwdmessage[fieldname].focusmsg);
					});
					$(this).bind('blur', function() {
						var wrap = $(this).parent().parent();
						if(!wrap.hasClass('error')) {
							$(this).siblings('span[class=help-inline]').text('');
						}
					});
				});
				//表单验证开始
				form.validate({
					onfocusout : function(element) { $(element).valid(); },
					onkeyup : false,
					onclick : false,
					focusInvalid: false,
					showErrors : function(errorMap, errorArr) {
						for(var i = 0; i < errorArr.length; i++) {
							var obj = $(errorArr[i].element);
							var wrap = obj.parent().parent();
							if(!wrap.hasClass('error')) {
								wrap.addClass('error');
							}
							obj.siblings('span[class=help-inline]').text(errorArr[i].message);	
						}
					},
					//验证规则
					rules : {
						'old_password': {required: true},
						'password': {required: true, passwordValidate:true},
						'repassword': {required: true, equalTo:"#input-password"},
						'verify': {required:true, verifyValidate:true}
					},
					submitHandler : function(forms) {
						var btn = $('button.js-ajax-submit');
						if(btn.data("loading")) {
							return false;
						}
						btn.data("loading",true);
						var text = btn.text();
						//按钮文案、状态修改
						btn.text('验证中...').prop('disabled', true).addClass('disabled');
						$(forms).ajaxSubmit({
							url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
							dataType : 'json',
							success : function(data, statusText, xhr, $form) {
								btn.removeProp('disabled').removeClass('disabled');
								btn.text('确定');
								btn.data("loading",false);
								if (data.state === 'success') {
									noty({text: data.info,
										type:'success',
										layout:'center'
									});
									setTimeout(function() {
										if (data.url) {
											window.location.href = data.url;
										} else {
											reloadPage(window);
										}
									}, 2500);
								} else if (data.state === 'fail') {
									var $verify_img = form.find(".verify_img");
									if($verify_img.length){
										$verify_img.attr("src",  $verify_img.attr("src")+"&refresh="+Math.random()); 
									}
									var $verify_input = form.find("[name='verify']").val("");
									noty({text: data.info,
										type:'error',
										layout:'center'
									});
								}
							}
						});
					}
				});
			});
		}
	});
	</script>
</body>
</html>